home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Graphics / Utility / GL Viewer 1.1.1 / src ƒ / macPrefsDLOG.c < prev    next >
Text File  |  1993-08-28  |  3KB  |  155 lines

  1. /*
  2.  * Routine to run GL View options dialog.
  3.  *
  4.  * Copyright (c) 1993 by Martin W. Fong
  5.  */
  6.  
  7.  
  8. #include <stdlib.h>
  9. #include "macPrefs.h"
  10.  
  11.  
  12. enum
  13. {
  14.     iOKOutline = Cancel + 1,
  15.  
  16.     __iFirstDialogItem__,
  17.  
  18.     iPrefSmallVideoC = __iFirstDialogItem__,
  19.     iPrefImageloop,
  20.     iPrefShowDirectory,
  21.     iPrefShowText,
  22.     iPrefPrintTheCodes,
  23.     iPrefQuiet,
  24.     iPrefVerbose,
  25.     iPrefImVerbose,
  26.  
  27.     __iLastDialogItem__ = iPrefImVerbose
  28. };
  29.  
  30.  
  31. static pascal void    DrawOutline (WindowPtr dialog, short item);
  32.  
  33.  
  34. #define SET_CHECK_BOX(ithItem, value)                                            \
  35. {                                                                                \
  36.     if (__iFirstDialogItem__ <= ithItem && ithItem <= __iLastDialogItem__)        \
  37.     {                                                                            \
  38.         GetDItem (dialog, ithItem, &iType, &hItem, &rect);                        \
  39.         if (iType & (ctrlItem | chkCtrl))                                        \
  40.             SetCtlValue ((ControlHandle) hItem, value);                            \
  41.     }                                                                            \
  42. }
  43.  
  44.  
  45. #define TOGGLE_PREF_SETTING(ithItem)                                            \
  46. {                                                                                \
  47.     if (__iFirstDialogItem__ <= ithItem && ithItem <= __iLastDialogItem__)        \
  48.     {                                                                            \
  49.         u_char    aMask = 0x01 << (__iLastDialogItem__ - ithItem);                \
  50.                                                                                 \
  51.                                                                                 \
  52.         if (newPrefs & aMask /* != 0 */)                                        \
  53.         {                                                                        \
  54.             newPrefs &= ~aMask;                                                    \
  55.             SET_CHECK_BOX (ithItem, 0);                                            \
  56.         }                                                                        \
  57.         else                                                                    \
  58.         {                                                                        \
  59.             newPrefs |= aMask;                                                    \
  60.             SET_CHECK_BOX (ithItem, 1);                                            \
  61.         }                                                                        \
  62.     }                                                                            \
  63. }
  64.  
  65.  
  66.     u_char
  67. DoMacPrefsDialog (u_char origPrefs)
  68.  
  69. {
  70.     u_char        newPrefs = origPrefs;
  71.     DialogPtr    dialog   = GetNewDialog (MACPREFSDLOG, (char *) NULL, (WindowPtr) -1);
  72.  
  73.  
  74.     if (dialog /* != (DialogPtr) NULL */)
  75.     {
  76.         short        iType;
  77.         Handle        hItem;
  78.         Rect        rect;
  79.         Boolean        fBreakLoop;
  80.         short        ithItem;
  81.         u_char        aMask;
  82.  
  83.  
  84.         /*...Prep outline field...*/
  85.  
  86.         GetDItem (dialog, iOKOutline, &iType, &hItem, &rect);
  87.  
  88.         if (iType == userItem | itemDisable)
  89.             SetDItem (dialog, iOKOutline, iType, (Handle) DrawOutline, &rect);
  90.  
  91.         /*...Establish the defaults...*/
  92.  
  93.         for (ithItem = __iLastDialogItem__, aMask = 0x01;
  94.              ithItem >= __iFirstDialogItem__;
  95.              ithItem--, aMask <<= 1)
  96.         {
  97.             if (origPrefs & aMask /* != 0 */)
  98.                 SET_CHECK_BOX (ithItem, 1);
  99.         }
  100.  
  101.         /*...Run the modal dialog...*/
  102.  
  103.         ShowWindow (dialog);
  104.  
  105.         for (fBreakLoop = FALSE; !fBreakLoop; )
  106.         {
  107.             short        item;
  108.  
  109.  
  110.             ModalDialog ((ProcPtr) NULL, &item);
  111.  
  112.             switch (item)
  113.             {
  114.                 case Cancel:
  115.                     newPrefs = origPrefs;
  116.                     /*    fall through    */
  117.  
  118.                 case OK:
  119.                     fBreakLoop = TRUE;
  120.                     break;
  121.  
  122.                 default:
  123.                 {
  124.                     TOGGLE_PREF_SETTING (item);
  125.                     break;
  126.                 }
  127.             }
  128.         }
  129.  
  130.         DisposDialog (dialog);
  131.     }
  132.  
  133.     return newPrefs;
  134. }
  135.  
  136.  
  137.     static pascal void
  138. DrawOutline (WindowPtr dialog, short item)
  139.  
  140. {
  141.     short    iType;
  142.     Handle    hItem;
  143.     Rect    rect;
  144.     GrafPtr    savePort;
  145.  
  146.  
  147.     GetPort (&savePort);
  148.     SetPort ((GrafPtr) dialog);
  149.         GetDItem (dialog, item, &iType, &hItem, &rect);
  150.         PenSize (3, 3);
  151.         FrameRoundRect (&rect, 16, 16);
  152.     SetPort (savePort);
  153. }
  154.  
  155.